package com.oraclejava.myactivityex;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

public class MyActivity extends Activity implements View.OnClickListener {

	EditText editText;
	Button btnOK;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initialize();

		String text = "";
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			text = extras.getString("text");
		}
		editText.setText(text);
		btnOK.setOnClickListener(this);
	}
	private void initialize(){
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.other);
		editText = (EditText) findViewById(R.id.editText1);
		btnOK = (Button) findViewById(R.id.button1);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == btnOK) {
			SharedPreferences pref = getSharedPreferences("PREVIOUS_RESULT",
					MODE_PRIVATE);
			SharedPreferences.Editor editor = pref.edit();
			editor.putString("text", editText.getText().toString());
			editor.commit();
			
			setResult(RESULT_OK);
			finish();
		}
	}
}
